<div class="detail-basic view-detail">
	<table class="pdetail">
		<tbody>
			<tr>
				<td colspan="11"><b>LÝ LỊCH THỰC TẬP SINH</b></td>
				<td rowspan="6" width="140">
				<?php 
				$logedInUser = User::model()->findByPk(Yii::app()->user->id);
				                                    
				if($modelProfile->photo_url == null || $modelProfile->photo_url == ""){
					echo CHtml::image("media/profile/no_image.jpg","",
					array("id" => "thumbnail","width"=>"140px" ,"height"=>"190px"));
				}else{
					$imgSrc = file_exists(PROFILE_FOLDER . $modelProfile->photo_url)? SITE_URL. "media/profile/" . $modelProfile->photo_url : SITE_URL. "media/profile/no_image.jpg";
					echo CHtml::image($imgSrc,"",
					array("id" => "thumbnail","width"=>"140px" ,"height"=>"190px"));
				}
				?>
			</td>
			</tr>
			<tr>
				<td class="yel"></td>
				<td colspan="8" align="center"></td>
				<td rowspan="2" class="yel">Giới tính</td>
				<td><img style="width: 16px"
					src="<?php echo Yii::app()->theme->baseUrl; ?>/images/icons-16/<?php echo ($modelProfile->sex == 1)?'box-checked':'box-unchecked'?>.png" />
					Nam</td>
			</tr>
			<tr>
				<td rowspan="2" class="yel">Họ và tên</td>
				<td colspan="8" rowspan="2" class="fullname" align="center"><?php echo Html::encode($modelProfile->full_name)?></td>
				<td><img style="width: 16px"
					src="<?php echo Yii::app()->theme->baseUrl; ?>/images/icons-16/<?php echo ($modelProfile->sex == 0)?'box-checked':'box-unchecked'?>.png" />
					Nữ</td>
			</tr>
			<tr>
				<td>Tuổi</td>
				<td align="center">
				<?php 
					$birthdate = new DateTime($modelProfile->birth_date);
					$today     = new DateTime();
					$interval  = $today->diff($birthdate);
					echo $interval->format('%y');
				?>
			</td>
			</tr>
			<tr>
				<td class="yel">Ngày sinh</td>
				<td align="center"><?php echo date('Y', strtotime($modelProfile->birth_date));?></td>
				<td align="center">Năm</td>
				<td align="center"><?php echo date('m', strtotime($modelProfile->birth_date));?></td>
				<td align="center">Tháng</td>
				<td align="center"><?php echo date('d', strtotime($modelProfile->birth_date));?></td>
				<td align="center">Ngày</td>
				<td align="center">Nơi sinh</td>
				<td align="center"><?php echo Html::encode($modelProfile->province->province_name)?></td>
				<td colspan="2" align="center"><?php echo Html::encode($modelProfile->province->region->region_name)?></td>
			</tr>
			<tr>
				<td class="yel">Địa chỉ liên lạc</td>
				<td colspan="10"><?php echo Html::encode($modelProfile->address)?></td>
			</tr>
		</tbody>
	</table>
</div>

<fieldset>
	<legend>Thêm thông tin cá nhân</legend>
	<table class="form" style="width: 100%">
		<tr>
			<td class="label"><?php echo $form->labelEX($model, 'code'); ?></td>
			<td class="input">
            <?php            
                echo $form->textField($model, 'code', array('style' => 'width:230px'));
                echo $form->error($model, 'code');
            ?>
        </td>
		</tr>
		<tr>
			<td class="label"><?php echo $form->labelEX($model, 'id_card_number'); ?></td>
			<td class="input">
            <?php            
                echo $form->textField($model, 'id_card_number', array('style' => 'width:230px'));
                echo $form->error($model, 'id_card_number');
            ?>
        </td>
		</tr>
		<tr>
			<td class="label"><?php echo $form->label($model, 'id_card_provided_date'); ?></td>
			<td class="input">
            <?php            
                echo $form->textField($model, 'id_card_provided_date', array('style' => 'width:230px', 'class' => 'datepicker', 'readonly'=>'true'));
                echo $form->error($model, 'id_card_provided_date');
           ?>
        </td>
		</tr>
		<tr>
			<td class="label"><?php echo $form->labelEX($model, 'id_card_provided_place'); ?></td>
			<td class="input">
            <?php            
                echo $form->textField($model, 'id_card_provided_place', array('style' => 'width:230px'));
                echo $form->error($model, 'id_card_provided_place');
            ?>
        </td>
		</tr>
		<tr>
			<td class="label"><?php echo $form->label($model, 'passport_number'); ?></td>
			<td class="input">
            <?php            
                echo $form->textField($model, 'passport_number', array('style' => 'width:230px'));
                echo $form->error($model, 'passport_number');
            ?>
        </td>
		</tr>
		<tr>
			<td class="label"><?php echo $form->label($model, 'passport_provided_date'); ?></td>
			<td class="input">
            <?php            
                echo $form->textField($model, 'passport_provided_date', array('style' => 'width:230px', 'class' => 'datepicker', 'readonly'=>'true'));
                echo $form->error($model, 'passport_provided_date');
            ?>
        </td>
		</tr>
		<tr>
			<td class="label"><?php echo $form->label($model, 'passport_provided_place'); ?></td>
			<td class="input">
            <?php            
                echo $form->textField($model, 'passport_provided_place', array('style' => 'width:230px'));
                echo $form->error($model, 'passport_provided_place');
            ?>
        </td>
		</tr>
	</table>	    
</fieldset>

<fieldset>
	<legend><?php echo $form->label($model, 'note'); ?></legend>
	<table style="width: 100%">
		<tr>	
			<td>
            <?php            
                echo $form->textArea($model, 'note', array('style' => 'width:387px; hight:60px'));
                echo $form->error($model, 'note');
            ?>
            </td>
	     </tr>
    <table>
</fieldset>

<fieldset>
	<legend>Thông tin trúng tuyển</legend>
	<table class="form" style="width: 100%">
		<tr>
			<td class="label"><?php echo $form->label($model, 'contract_number'); ?></td>
			<td class="input">
	            <?php            
	                echo $form->textField($model, 'contract_number', array('style' => 'width:230px'));
	                echo $form->error($model, 'contract_number');
	            ?>
	        </td>
		</tr>
		<tr>
			<td class="label"><?php echo $form->label($model, 'dispatching_company'); ?></td>
			<td class="input">
	            <?php            
	                echo $form->textField($model, 'dispatching_company', array('style' => 'width:230px'));
	                echo $form->error($model, 'dispatching_company');
	            ?>
	        </td>
		</tr>
		<tr>
			<td class="label"><?php echo $form->label($model, 'hiring_company_id'); ?></td>
			<td class="input">            
	            <div id="popupCreateUnion"></div>
	            <?php
	            echo Html::customDropDownList($model, 'hiring_company_id', HiringCompany::model()->getChtmlDropdownData(), 'id', 'name', array('salary', 'management_fee', 'introducing_fee', 'union->name'), t('DROPDOWN_FIRST_ITEM_HIRING_COMPANY', 'advanceProfile'), 'width:238px');
	            if($logedInUser->isAdmin() || $logedInUser->isSuperAdmin()) {
	            	echo Html::buttonPopup('button-add-new-hiring', "+", url('/hiringcompany/create'), 'Thêm mới', 'Thêm mới công ty tiếp nhận', 'update-dialog-open-link add-partial', 500, 450);
	            }            	            
	            ?>
	        </td>
		</tr>
        <tr>
			<td class="label"><?php echo t('LBL_NAME', 'union') ?></td>
			<td class="input">
	            <input type="text" value="<?php 
	            	if($model->hiringCompany != null)           
	                	//echo $form->textField($model->hiringCompany->union, 'name', array('id' => 'textfield_union_name', 'style' => 'width:230px', 'readonly' => true));
	            		echo Html::encode($model->hiringCompany->union->name);
	            	else
	            		echo '';
	            ?>" id="textfield_union_name" readonly=true  style = 'width:230px'/>
	        </td>
		</tr>
		
        <?php        	
        	if ($logedInUser->isAdmin() || $logedInUser->isSuperAdmin()){
			echo '<tr>
					<td class="label">'; 
					echo $form->label($model, 'salary');
				echo '</td>
			        <td class="input">';
	                	echo $form->textField($model, 'salary', array('id' => 'textfield_salary', 'style' => 'width:230px'));
	                	echo $form->error($model, 'salary');
		        echo'</td>
		        </tr>
		        <tr>
			        <td class="label">Phí quản lý</td>
			        <td class="input">';
				        echo $form->textField($model, 'management_fee', array('id' => 'textfield_management_fee', 'style' => 'width:230px'));
				        echo $form->error($model, 'management_fee');
			    echo '</td>
		        </tr>
		        <tr>
			        <td class="label">Phí môi giới</td>
			        <td class="input">';
					    echo $form->textField($model, 'introducing_fee', array('id' => 'textfield_introducing_fee', 'style' => 'width:230px'));
					    echo $form->error($model, 'introducing_fee');
			    echo ' </td>
			    </tr>';
		    }
	    ?>
	<tr>
			<td class="label">
    		<?php echo $form->labelEx($model, 'introducing_company_id'); ?>
        </td>
			<td class="input">         
            <?php
            	echo $form->dropDownList($model, 'introducing_company_id', IntroducingCompany::model()->getChtmlDropdownData(), array('style' => 'width:238px', 'empty' => t('DROPDOWN_FIRST_ITEM_INTRODUCING_COMPANY', 'advanceProfile')));
            	if($logedInUser->isAdmin() || $logedInUser->isSuperAdmin()) {            	
            		echo Html::buttonPopup('button-add-new-introducing', "+", url('/Introducingcompany/create'), 'Thêm mới', 'Thêm mới công ty tiến cử', 'update-dialog-open-link add-partial', 500, 400);
            	}
            ?>
    	</td>
		</tr>
		<tr>
			<td class="label"><?php echo $form->labelEX($model, 'apply_date'); ?></td>
			<td class="input">
            <?php            
                echo $form->textField($model, 'apply_date', array('style' => 'width:230px', 'class' => 'datepicker', 'readonly'=>'true'));
                echo $form->error($model, 'apply_date');
            ?>
        </td>
		</tr>
		<tr>
			<td class="label"><?php echo $form->label($model, 'selected_date'); ?></td>
			<td class="input">
            <?php            
                echo $form->textField($model, 'selected_date', array('style' => 'width:230px', 'class' => 'datepicker', 'readonly'=>'true'));
                echo $form->error($model, 'selected_date');
            ?>
        </td>
		</tr>
		<tr>
			<td class="label"><?php echo $form->label($model, 'order'); ?></td>
			<td class="input">
            <?php            
                echo $form->textField($model, 'order', array('style' => 'width:230px'));
                echo $form->error($model, 'order');
            ?>
        </td>
		</tr>
		<tr>
			<td class="label"><?php echo $form->labelEX($model, 'contract_duration'); ?></td>
			<td class="input">
            <?php            
                echo $form->textField($model, 'contract_duration', array('style' => 'width:230px'));
                echo $form->error($model, 'contract_duration');
            ?>
        </td>
		</tr>
		<tr>
			<td class="label"><?php echo $form->labelEX($model, 'complete_contract_date'); ?></td>
			<td class="input">
            <?php            
                echo $form->textField($model, 'complete_contract_date', array('style' => 'width:230px', 'readonly'=>'true'));
            ?>
        </td>
		</tr>
		<tr>
			<td class="label"><?php echo $form->labelEX($model, 'back_date_before_contract'); ?></td>
			<td class="input">
            <?php            
                echo $form->textField($model, 'back_date_before_contract', array('style' => 'width:230px', 'class' => 'datepicker', 'readonly'=>'true'));
            ?>
        </td>
		</tr>
	</table>
</fieldset>

<fieldset>
	<legend>Thông tin chuyến bay</legend>
	<table class="form" style="width: 100%">
		<tr>
			<td class="label"><?php echo $form->label($model, 'go_date'); ?></td>
			<td class="input">
            <?php            
                echo $form->textField($model, 'go_date', array('style' => 'width:230px', 'readonly'=>'true'));
                echo $form->error($model, 'go_date');
            ?>
        </td>
		</tr>
		<tr>
			<td class="label"><?php echo $form->label($model, 'arrive_city'); ?></td>
			<td class="input">
            <?php            
                echo $form->textField($model, 'arrive_city', array('style' => 'width:230px'));
                echo $form->error($model, 'arrive_city');
            ?>
        </td>
		</tr>
		<tr>
			<td class="label"><?php echo $form->label($model, 'flight'); ?></td>
			<td class="input">
            <?php            
                echo $form->textField($model, 'flight', array('style' => 'width:230px'));
                echo $form->error($model, 'flight');
            ?>
        </td>
		</tr>
		<tr>
			<td class="label"><?php echo $form->labelEX($model, 'visa_address'); ?></td>
			<td class="input">
        	<?php
            	echo $form->textField($model, 'visa_address', array('style' => 'width:230px'));
                echo $form->error($model, 'visa_address');
			?>
        </td>
		</tr>		
	</table>
</fieldset>

<fieldset>
	<legend>Tập tin đính kèm</legend>
	<table>
		<tr>
			<td><?php echo Html::buttonPopup('button-add-new-attachment', "Thêm tệp tin", url('attachment/createattachment', array('profile_id' => $modelProfile->id)), 'Thêm mới', 'Thêm mới tệp tin đính kèm', 'button update-file-dialog-open-link', 500, 300);?> </td>
			<td><?php echo Html::buttonDelete('button-delete-attachment', 'Xóa tệp tin', 'Xóa tệp tin', 'attachment/delete');?></td>
		</tr>
	</table>
	<br /> 
	<?php
		$this->widget ( 'GridView', array (
				'id' => 'DataGrid',
				'dataProvider' => Attachment::model()->loadAttachmentsByProfile($modelProfile->id),
				'itemsCssClass' => 'grid',
				'summaryText' => LGHelpers::getSummary (),
				'columns' => array (
					array (
							'header' => '#',
							'class' => 'CCheckBoxColumn',
							'selectableRows' => '2',
							'htmlOptions' => array (
									'width' => '10px',
									'style' => 'text-align:center' 
							),
							'id' => 'chkId' 
					),
					array (
							'name' => 'name',
							'value' => 'CHtml::link(CHtml::encode($data->name), Yii::app()->baseUrl . "/../media/attachment/" .$data->file_name, array("target"=>"_blank"))',
							'header' => t('LBL_NAME', 'attachment'),
							'headerHtmlOptions' => array (									
									'style' => 'text-align:left' 
							),
							'type' => 'raw' 
					),
				) 
		) );
		?>
</fieldset>

<script type="text/javascript">LGCMS.addTooltip();</script>
<script type="text/javascript">
	LGCMS.addTooltip();
	$(function() {
	    $(".datepicker").datepicker({
	        'dateFormat': 'dd-mm-yy',
	        changeMonth: true,
	        changeYear: true,
	        'buttonImage': '<?php echo themeUrl(); ?>/images/datepicker.gif',
            'showOn': 'both',
            'buttonImageOnly': 'true',
            'buttonText': "Chọn ngày",
            'showAnim': 'slideDown',
            'yearRange': '-60:+0',
	    });
	});

	$('#AdvanceProfile_hiring_company_id').change(function(){			
		if($(this).find('option:selected').attr('data') != undefined)
		{
			var data = $(this).find('option:selected').attr('data').split('||');
			$("#textfield_salary").val(data[0]);
        	$("#textfield_management_fee").val(data[1]);
        	$("#textfield_introducing_fee").val(data[2]);
        	$("#textfield_union_name").val(data[3]);
		}
		else
		{			
			$("#textfield_salary").val('');
        	$("#textfield_management_fee").val('');
        	$("#textfield_introducing_fee").val('');
        	$("#textfield_union_name").val('');
		}
	});
	
	$(function() {
	    $('#AdvanceProfile_go_date').datepicker({
	        'dateFormat': 'dd-mm-yy',
	        changeMonth: true,
	        changeYear: true,
	        'buttonImage': '<?php echo themeUrl(); ?>/images/datepicker.gif',
            'showOn': 'both',
            'buttonImageOnly': 'true',
            'buttonText': "Chọn ngày",
            'showAnim': 'slideDown',
            'yearRange': '-60:+0',
            onSelect: function(dateText, inst){
            	var go_date = $(this).datepicker('getDate');
            	if($('#AdvanceProfile_contract_duration').val() != null & $('#AdvanceProfile_contract_duration').val() != ''){
        			var num_of_month = $('#AdvanceProfile_contract_duration').val() * 12;
        			go_date.setMonth(go_date.getMonth() + num_of_month);
        			$('#AdvanceProfile_complete_contract_date').datepicker('setDate', go_date);
        		}else{
        			$('#AdvanceProfile_complete_contract_date').val('');
        		}
            }
	    });
	});
	$(function() {
	    $('#AdvanceProfile_complete_contract_date').datepicker({
	        'dateFormat': 'dd-mm-yy',
	        changeMonth: true,
	        changeYear: true,
            'buttonText': "Chọn ngày",
            'showAnim': 'slideDown',
            'yearRange': '-60:+0',
            'disabled': 'true'
	    });
	});
	$('#AdvanceProfile_contract_duration').change(function(){
		var go_date = $('#AdvanceProfile_go_date').datepicker('getDate');
		if($('#AdvanceProfile_contract_duration').val() != null & $('#AdvanceProfile_contract_duration').val() != ''){
			var num_of_month = $('#AdvanceProfile_contract_duration').val() * 12;
			go_date.setMonth(go_date.getMonth() + num_of_month);
			$('#AdvanceProfile_complete_contract_date').datepicker('setDate', go_date);
		}else{
			$('#AdvanceProfile_complete_contract_date').val('');
		}
	});
	
	$('#button_upload_visa').click(function(){
		$('#selectVisaFile').trigger('click');
		return false;
	});
	function uploadVisaFile() {
		var oFReader = new FileReader();
		var file = $('#selectVisaFile')[0].files[0];
		$('#AdvanceProfile_url_visa').val(file.name);
	};

	$('#button_upload_contract').click(function(){
		$('#selectContractFile').trigger('click');
		return false;
	});
	function uploadContractFile() {
		var oFReader = new FileReader();
		var file = $('#selectContractFile')[0].files[0];
		$('#AdvanceProfile_url_contract').val(file.name);
	};

 	$('#button_upload_id_card_photo').click(function(){
 		$('#selectIdCardPhotoFile').trigger('click');
 		return false;
 	});
 	function uploadIdCardPhotoFile() {
 		var oFReader = new FileReader();
 		var file = $('#selectIdCardPhotoFile')[0].files[0];
 		$('#AdvanceProfile_url_id_card_photo').val(file.name);
 	};
	
	$(document).ready(function () {
        $("a[rel=zoom]").fancybox({
            "transitionIn": "elastic",
            "transitionOut": "elastic"
        });
    });

    function processAfterNewHiring()
    {
    	$.ajax({
            url: '<?php echo url('/Hiringcompany/detail/');?>?id='+arguments[0],
            type: "get",
            dataType: "json",
            cache: false,
            success: function(response){      
            	var option = '<option value="'+response.id+'" data="'+response.salary+'||'+response.management_fee+'||'+response.introducing_fee+'||'+response.union.name+'">'+response.name+'</option>';		        
 		        $("#AdvanceProfile_hiring_company_id").append(option);
 		        $("#AdvanceProfile_hiring_company_id").find('option[value="'+response.id+'"]').prop('selected', true); 		        

            	$("#textfield_salary").val(response.salary);
            	$("#textfield_management_fee").val(response.management_fee);
            	$("#textfield_introducing_fee").val(response.introducing_fee);   
            	$("#textfield_union_name").val(response.union.name);         		                  	      		           		             
            }
        });
    }

    function processAfterNewIntroducing()
    {
    	$.ajax({
            url: '<?php echo url('/Introducingcompany/detail/');?>?id='+arguments[0],
            type: "get",
            dataType: "json",
            cache: false,
            success: function(response){            		
            	var option = '<option value="'+response.id+'"	>'+response.name+'</option>';		        
 		        $("#AdvanceProfile_introducing_company_id").append(option);
 		        $("#AdvanceProfile_introducing_company_id").find('option[value="'+response.id+'"]').prop('selected', true);          		                  	      		           		            
            }
        });
    }

	$("#button_add_new_union").click(function() {
		popupCreateUnion = $('#popupCreateUnion');
		popupCreateUnion.html( '<div class="ajax-loader" ></div>');
		popupCreateUnion.dialog({			
			modal: true,
			width: 470,
			height: 300,
			title: 'Thêm mới Nghiệp đoàn'
		});
		$.ajax({
            url: '<?php echo url('/union/create');?>',
            type: "post",
            dataType: "json",
            cache: false,
            success: function(response){            		
            	popupCreateUnion.html(response.content);	            		           		               
            }
        });
    });

	$("#buttonDeleteAttachment").click(function()
	{
		var _ids = $.fn.yiiGridView.getChecked('DataGrid','chkId');
		if(_ids.length == 0){
			$("#buttonDeleteAttachment").removeAttr('onclick');
			LGCMS.kAlert('Xóa tệp tin đính kèm', 'Vui lòng chọn ít nhất một tệp tin trước khi thực hiện lên này', 450, 150);
		}else{	
	   		window.location.href = $('#buttonDeleteAttachment').attr('action') + '?id=' + $.fn.yiiGridView.getChecked('DataGrid','chkId');		
	   	}
	});

	$(document).ready(function () {
		// Allow only numeric (0-9) in input text --------------------
		$("#AdvanceProfile_complete_contract_date").keydown(function (event) {
			//console.log(event.keyCode);
			// Allow only backspace, delete, key right and key left
			if (event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 37 ||
				event.keyCode == 39) {
				// leave it empty.
			}
			else {
				if (event.keyCode == 13) {
					// Enter - Do post back
				}
				// Ensure that it is a number and stop the keypress
				else if (event.keyCode < 48 || event.keyCode > 57) {
					event.preventDefault();
					// Show message to the user
					$("#AdvanceProfile_complete_contract_date_em_").show();
					$("#AdvanceProfile_complete_contract_date_em_").html("Type numbers only.");
				}
				else {
					// A number is pressed so we hide the message
					$("#AdvanceProfile_complete_contract_date_em_").hide();
				}
			}
		}); // end keydown
	}); // end ready
</script>
